package subject_set.offer100;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @author haomin
 * @date 2022/10/13 21:09
 **/
public class Offer09 {
    class CQueue {
        Deque<Integer> stack1; // 在s1栈尾插
        Deque<Integer> stack2; // 在s2栈删除头

        public CQueue() {
            stack1 = new LinkedList<>();
            stack2 = new LinkedList<>();
        }

        public void appendTail(int value) {
            stack1.push(value);
        }

        public int deleteHead() {
            if(!stack2.isEmpty()) return stack2.poll();
            else {
                while(!stack1.isEmpty()) stack2.push(stack1.poll());
                return stack2.isEmpty() ? -1 : stack2.poll();
            }
        }
    }
}